//
//  ViewController.swift
//  lesson8闭包函数循环引用问题
//
//  Created by 张建 on 2018/3/16.
//  Copyright © 2018年 micheal. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var callBackBlock : (()->())?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //Swift中闭包循环引用使用weak进行处理即可
        weak var weakSelf = self
        loadData {
            print("回到主线程刷新界面!")
            weakSelf!.view.backgroundColor = UIColor.red
        }
        
//        DispatchQueue.global().async {
//            print("执行耗时操作!")
//            DispatchQueue.main.async {
//
//                self.view.backgroundColor = UIColor.black
//            }
//        }
    }

    func loadData(callBackBlock:@escaping ()-> ()) {
        
        print("执行耗时操作!")
        self.callBackBlock = callBackBlock
        callBackBlock()
    }
    
    deinit {
        print("该对象销毁！")
    }

}

